#pragma once

#ifndef FRAME_H
#define FRAME_H

#include "camera.h"
#include "common.h"


namespace myslam
{
    //forward declare
    struct MapPoint;
    struct Feature;

    /**
    * 帧
    * 每一帧分配独立的id，关键帧分配关键帧id
    */
    struct Frame
    {
    public:
        EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
        typedef std::shared_ptr<Frame> Ptr;
        
        unsigned long id_=0;           //id of the frame;
        unsigned long keyframe_id_=0;  //id of key frame
        bool is_keyframe_=false;       //是否为关键帧
        double time_stamp_;            //时间戳
        
        SE3 pose_;                     // Tcw形式pose
        std::mutex pose_mutex_;        //pose数据锁
        cv::Mat left_img_, right_img_; //stereo images
        
        //extracted feature in left image
        std::vector<std::shared_ptr<Feature>> feature_left_;
        //corresponding features in right iamge, set to nullptr if no corresponding
        std::vector<std::shared_ptr<Feature>> features_right;
        
    public: //data members
        Frame () {}
        Frame(long id, double time_stamp, const SE3 &pose, const Mat &left,
              const Mat &right);
        
        //set and get pose, thread safe
        SE3 pose()
        {
            std::unique_lock<std::mutex> lck(pose_mutex_);
            return pose_;
        }
        
        void SetPose(const SE3 &pose)
        {
            std::unique_lock<std::mutex> lck(pose_mutex_)
            pose_pose;
        }
        
        //设置关键帧并分配帧id
        void SetKeyFrame();
        
        //工厂构建模式，分配id
        static  std::shared_ptr<Frame> CreateFrame();
    };
} //namespace myslam

#endif //MYSLAM_FRAME_H
            
        
        


#endif // FRAME_H
